package cn.itlaobing.web.repository;

import cn.itlaobing.web.entity.SystemUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

public interface ISystemUserRepository  extends JpaRepository<SystemUser,Long> {
    /*
    * 根据用户名查询用户是否存在
    * */
    SystemUser findByUserAccount(String userAccount);
    /*
    * 根据用户名和密码查询用户是否存在
    * */
    SystemUser findByUserAccountAndUserPass(String userAccount, String userpass);

    @Transactional
    @Modifying
    @Query("update SystemUser s set s.headImage = ?2,s.updateTime=?3 where s.id=?1 ")
    int updateHeadImgById(Long id, String headimg, Timestamp time);

    @Transactional
    @Modifying
    @Query("update SystemUser s set s.userPass = ?2,s.updateTime=?3 where s.id=?1 ")
    int updatePassById(Long id, String newpass, Timestamp time);

    @Transactional
    @Modifying
    @Query("update SystemUser s set s.lastLoginTime = ?2,s.updateTime=?2,s.islogin=?3 where s.id=?1 ")
    int updateLoginById(Long id, Timestamp time, int islogin);
}
